<template>
  <ms-dialog :title="title" :dialog-visible="dialogVisible" @show="showDialog" @ok="handleSaveForm" @close="handleCloseDialog">
    <el-form v-loading="loading" label-width="80px" ref="formValid" :rules="rules" :model="form">
<#if forms??>
      <#list forms as column>
      <el-form-item label="${column.label}" prop="${column.colName}">
      <#if column.formType = "dict">
        <ms-dict dict-type="${column.dictValue}" type="${column.dictType}" v-model="form.${column.colName}" />
      <#elseif column.formType = "date">
        <ms-date-picker v-model="form.${column.colName}" />
      <#elseif column.formType = "editor">
        <ms-editor v-model="form.${column.colName}" ref="editor${column.colName}" />
      <#else>
        <el-input v-model<#if column.colType="Integer">.number</#if>="form.${column.colName}" />
      </#if>
      </el-form-item>
      </#list>
</#if>
<#if files??>
    <#list files as column>
      <el-form-item label="${column.name}">
        <ms-upload
          file-path="${column.filePath}"
          @fileList="getFile"
          process-id="${column.processId}"
          <#if column.multiple>multiple</#if>
          ref="file${column.processId}"
          :limit="${column.limits}"
          list-type="${column.listType}"
        />
      </el-form-item>
    </#list>
</#if>
    </el-form>
  </ms-dialog>
</template>

<script>
import MsDialog from '@/common/dialog'
import tip from '@/mixins/tip'
<#if isFile>
import MsUpload from '@/common/upload/components'
</#if>
<#if isDict>
import MsDict from '@/common/dict/components'
</#if>
<#if isDate>
import MsDatePicker from '@/common/datePicker'
</#if>
<#if isEditor>
import MsEditor from '@/common/editor/components'
</#if>
const preFixUrl = '/${package}/${changeClassName}/'
export default {
  components: {
    MsDialog<#if isFile>,
    MsUpload</#if><#if isDict>,
    MsDict</#if><#if isDate>,
    MsDatePicker</#if><#if isEditor>,
    MsEditor</#if>
  },
  mixins: [tip],
  data() {
    return {
      apiUrl: {
        get: `${r'${preFixUrl}'}getById`,
        save: `${r'${preFixUrl}'}save`
      },
      rules: {
        <#if forms??>
        <#list forms as column>
        ${column.colName}: [
        <#if column.notBlank>
          { required: true, message: '请输入${column.label}', trigger: 'blur' },
        </#if>
        <#if column.minLength?? || column.maxLength??>
          { <#if column.maxLength??>max: ${column.maxLength},</#if><#if column.minLength??> min: ${column.minLength}</#if>, message: '${column.label}长度不正确', trigger: 'blur' },
        </#if>
        <#if column.regxpRule??>
          { pattern: ${column.regxpRule}, message: '请输入正确格式${column.label}', trigger: 'blur' }
        </#if>
        ],
        </#list>
        </#if>
      }
    }
  }
}
</script>
